import json

import requests
from lxml import etree
import re
import js

url = 'https://y.qq.com/n/ryqq/toplist/26'
res = requests.get(url)
res = res.text
html_tree = etree.HTML(res)
datas = html_tree.xpath("//ul[@class='songlist__list']/li")
print(datas)
# for data in datas:
#     rank = data.xpath(
#         ".//div[contains(@class,'songlist__item')]/div[contains(@class,'songlist__number')]/text()")[
#         0]
#     title = data.xpath(".//div[@class='songlist__songname']/span[@class='songlist__songname_txt']/a[2]/text()")[0]
#     author = data.xpath(
#         ".//div[contains(@class,'songlist__item')]/div[@class='songlist__artist']/a[@class='playlist__author']/text()")[
#         0]
#     print(rank, title, author)
# print(res)
json_data = re.search(r'window.__INITIAL_DATA__ =(.*?)</script>', res)
json_data = json_data.group(1)
json_data = re.sub(r'undefined', 'null', json_data)
json_data = json.loads(json_data)
for song in json_data['songInfoList']:
    print(song)
